package com.wkhyapp.lm.weigit.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wkhyapp.lm.R;
import com.wkhyapp.lm.utils.StringUtils;

/**
 * Created by fang on 2021/10/15.
 */

public class ContactShopDialog {
    private Dialog mDialog;
    private Context mContext;
    private View dialog_view;
    public ContactShopDialog.callBack mCallBack;
    RelativeLayout weixin_rl;
    RelativeLayout phone_rl;
    private String phone,wx;
    private TextView  phoe_tv,weixin_tv;
    RelativeLayout save_rl;
    public ContactShopDialog(Context context, String wx, String phone) {
        this.mContext = context;
        this.phone = phone;
        this.wx = wx;
        init();
    }

    public void init() {
        mDialog = new Dialog(mContext, R.style.custom_dialog);
        dialog_view = LayoutInflater.from(mContext).inflate(R.layout.dialog_shop_other, null);
        weixin_rl = (RelativeLayout) dialog_view.findViewById(R.id.weixin_rl);
        phone_rl = (RelativeLayout) dialog_view.findViewById(R.id.phone_rl);
        save_rl = (RelativeLayout) dialog_view.findViewById(R.id.save_rl);
        phoe_tv = (TextView) dialog_view.findViewById(R.id.phoe_tv);
        weixin_tv = (TextView) dialog_view.findViewById(R.id.weixin_tv);
        mDialog.setContentView(dialog_view);

        phoe_tv.setText("电话 "+phone);
        weixin_tv.setText("微信 "+wx);

        final Window window = mDialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.CENTER; // 居中位置
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);

        weixin_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.weixin(wx);
            }
        });

        if(StringUtils.isEmpty(phone)){
            phone_rl.setVisibility(View.GONE);
        }


        phone_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.phone(phone);
            }
        });
        save_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
            }
        });
    }

    public void close() {
        mDialog.dismiss();
    }

    public void show() {
        mDialog.show();
    }

    public void setCallBack(ContactShopDialog.callBack callBack) {
        this.mCallBack = callBack;
    }


    public interface callBack {
        void weixin(String str);
        void phone(String str);
    }
}